﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Profile;
using DTO;
using System.Web.Security;

namespace BLL
{
    public class BasePage:System.Web.UI.Page
    {
        public ProfileBase PageProfile;
        public BasePage()
        {
            PageProfile = Helpers.GetUserProfile();
        }

        protected override void InitializeCulture()
        {
            string culture = "en-CA";
            this.Culture = culture;
            this.UICulture = culture;
        }

        protected override void OnPreInit(EventArgs e)
        {
            string id = Globals.ThemesSelectorID;
            if (id.Length > 0)
            {
                // if this is a postback caused by the theme selector's dropdownlist, retrieve
                // the selected theme and use it for the current page request
                if (this.Request.Form["__EVENTTARGET"] == id && !string.IsNullOrEmpty(this.Request.Form[id]))
                {
                    this.Theme = this.Request.Form[id];
                    Helpers.SetProfileTheme(PageProfile, Theme);
                }
                else if (!string.IsNullOrEmpty(Helpers.GetProfileTheme(PageProfile)))
                {
                    Theme = Helpers.GetProfileTheme(PageProfile);
                }
            }
            base.OnPreInit(e);
        }

        protected override void OnLoad(EventArgs e)
        {
            // add onfocus and onblur javascripts to all input controls on the forum,
            // so that the active control has a difference appearance
            Helpers.SetInputControlsHighlight(this, "highlight", false);

            base.OnLoad(e);
        }

        public string BaseUrl
        {
            get
            {
                string url = this.Request.ApplicationPath;
                if (url.EndsWith("/"))
                    return url;
                else
                    return url + "/";
            }
        }

        public string FullBaseUrl
        {
            get
            {
                return this.Request.Url.AbsoluteUri.Replace(
                   this.Request.Url.PathAndQuery, "") + this.BaseUrl;
            }
        }

        protected void RequestLogin()
        {
            this.Response.Redirect(FormsAuthentication.LoginUrl +
               "?ReturnUrl=" + this.Request.Url.PathAndQuery);
        }

        public string FormatPrice(object price)
        {
            //return Convert.ToDecimal(price).ToString("N2") + " " + Globals.Settings.Store.CurrencyCode;
            return Convert.ToDecimal(price).ToString("N2") + " VND"; 
        }


    }
}